function LogPanel() {
}

LogPanel.instance = LogPanel;

LogPanel.faceUrl = "logController";

LogPanel.systemLogDatagrid = null;

LogPanel.systemLogPager = null;

// 初始
LogPanel.init = function() {
	LogPanel.systemLogDatagrid = mini.get("systemLogDatagrid");
	LogPanel.systemLogPager = mini.get("systemLogPager");
	LogPanel.renderer();
	LogPanel.reload();
};

//加载数据
LogPanel.reload = function() {
	LogPanel.loadData(LogPanel.systemLogPager.pageIndex, LogPanel.systemLogPager.pageSize);
};

//页码条改变事件
LogPanel.pagechanged = function(e){
	LogPanel.loadData(e.pageIndex, e.pageSize);
};

/**
 * 传入页数和每页显示树查找数据
 */
LogPanel.loadData = function(index, size) {

	var params = {};
	params.method = 'find';
	params.pageNo = index;
	params.size = size;
	$.ajax( {
		type: 'POST',
		dataType: 'json',
		url: __root+"/"+LogPanel.faceUrl,
		cache: false,
		data: params,
		success: function(json) {
			LogPanel.systemLogPager.setTotalCount(json.rowCount);
			LogPanel.systemLogDatagrid.loadData(json.resultList);
		},
		error: function(obj, ertxt) { /* 失败回调函数.这里是网络失败, 比如500错误等 */
			mini.alert("初始化数据错误：" + ertxt);
		}
	});
};

/**
 * 对表格的时间数据渲染
 */
LogPanel.renderer = function() {
	LogPanel.systemLogDatagrid.on("drawcell", function(e) {
		var field = e.field, value = e.value;
		if (field == "optTime") {
			if (value != null) {
				e.cellHtml = XMAppUtils.formatDate(null, XMAppUtils.obj2DateTime(value));
			}
		}
	});
};

/**
 * 删除日志
 */
LogPanel.del = function() {
	
	var rowData = LogPanel.systemLogDatagrid.getSelecteds();
	
	if(!rowData){
		mini.alert("请选中要删除的记录！");
	}else{
		mini.confirm("确定要删除选中的日志？", "删除日志",
	            function (action) {      
	                if (action == "ok") {
	                	var ids = new Array();
	            		for ( var i = 0; i < rowData.length; i++) {
	            			ids.push(rowData[i].id);
	            		}
	            		$.ajax( {
	            			type: 'POST',
	            			dataType: 'json',
	            			url: __root+"/"+LogPanel.faceUrl,
	            			data: {
	            				method: 'delete',
	            				id: ids
	            			},
	            			success: function(text) {
	            				LogPanel.reload();
	            			},
	            			error: function(obj, error) {
	            				LogPanel.reload();
	            			}
	            		});
	                }
		});
	}
};

LogPanel.delall = function(){
	mini.alert("开发中...");
};